package com.zengqingfa.examples.mybatisplus.rest;

import cn.hutool.extra.spring.SpringUtil;
import com.zengqingfa.examples.mybatisplus.chain.FilterChain;
import com.zengqingfa.examples.mybatisplus.chain.PreparationList;
import com.zengqingfa.examples.mybatisplus.response.Result;
import com.zengqingfa.examples.mybatisplus.strategy.ProcessStrategyContext;
import com.zengqingfa.examples.mybatisplus.util.SpringContextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 *
 * @fileName: ChainController
 * @author: zengqf3
 * @date: 2021-4-8 17:47
 * @description:
 */
@RestController
@RequestMapping("/chain")
public class ChainController {

    @Resource
    SpringContextUtils springContextUtils;

    @PostMapping("/check")
    public Result check(@RequestBody PreparationList preparationList) {
        FilterChain filterChain = springContextUtils.getBean(FilterChain.class);
        boolean b = filterChain.doFilter(preparationList, filterChain);
        if(!b){
           throw new RuntimeException("校验不通过");
        }
        return Result.success(true);
    }
}
